<template>
  <div class="ranking-board">
    <h3>全站排行榜</h3>
    <ul class="ranking-list">
      <li 
        v-for="item in rankingList" 
        :key="item.id" 
        class="ranking-item" 
        @click="handleRankingItemClick(item.id)"
      >
        <span 
          class="ranking-num" 
          :class="{ 
            'top1': item.rank === 1, 
            'top2': item.rank === 2, 
            'top3': item.rank === 3 
          }"
        >
          {{ item.rank }}
        </span>
        <div class="ranking-content">
          <span class="ranking-title">{{ item.title }}</span>
          <div class="ranking-meta">
            <span class="ranking-author">{{ item.author }}</span>
            <span class="ranking-duration">{{ item.duration }}</span>
          </div>
        </div>
        <div class="ranking-stats">
          <span class="ranking-views">{{ item.views }}</span>
          <span class="ranking-trend" :class="`trend-${item.trend}`">
            <i v-if="item.trend === 'up'" class="fas fa-arrow-up"></i>
            <i v-else-if="item.trend === 'down'" class="fas fa-arrow-down"></i>
            <i v-else-if="item.trend === 'stable'" class="fas fa-minus"></i>
            <i v-else class="fas fa-plus"></i>
            {{ item.trend === 'new' ? '新' : (item.trend === 'stable' ? '' : item.changeCount) }}
          </span>
          <span v-if="item.hotTag" class="ranking-hot-tag">{{ item.hotTag }}</span>
        </div>
      </li>
    </ul>
    <a href="#" class="ranking-more" @click.prevent="handleViewFullRanking">查看完整榜单</a>
  </div>
</template>

<script>
export default {
  name: 'RankingBoard',
  props: {
    rankingList: {
      type: Array,
      default: () => [],
    },
  },
  methods: {
    handleRankingItemClick(videoId) {
      this.$emit('item-click', videoId)
    },
    handleViewFullRanking() {
      this.$emit('view-full-ranking')
    },
  },
}
</script>

<style scoped>
.ranking-board {
  background: white;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.ranking-board h3 {
  margin: 0 0 12px 0;
  font-size: 16px;
  font-weight: 600;
  color: #333;
}

.ranking-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.ranking-item {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  transition: all 0.3s ease;
}

.ranking-item:last-child {
  border-bottom: none;
}

.ranking-item:hover {
  background-color: rgba(0, 123, 255, 0.05);
  transform: translateX(4px);
}

.ranking-num {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  font-size: 14px;
  font-weight: 600;
  color: #999;
  margin-right: 12px;
}

.ranking-num.top1 {
  background-color: #ff6b6b;
  color: white;
  border-radius: 4px;
}

.ranking-num.top2 {
  background-color: #ffaf40;
  color: white;
  border-radius: 4px;
}

.ranking-num.top3 {
  background-color: #4ecdc4;
  color: white;
  border-radius: 4px;
}

.ranking-content {
  flex: 1;
  min-width: 0;
}

.ranking-title {
  display: block;
  font-size: 14px;
  color: #333;
  line-height: 1.4;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ranking-meta {
  display: flex;
  gap: 8px;
  font-size: 12px;
  color: #999;
}

.ranking-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #999;
}

.ranking-views {
  color: #666;
}

.ranking-trend {
  display: flex;
  align-items: center;
  gap: 2px;
}

.ranking-trend.trend-up {
  color: #ff4d4f;
}

.ranking-trend.trend-down {
  color: #52c41a;
}

.ranking-trend.trend-stable {
  color: #999;
}

.ranking-trend.trend-new {
  color: #1890ff;
}

.ranking-hot-tag {
  padding: 2px 6px;
  background: #fee;
  color: #ff4d4f;
  border-radius: 3px;
  font-size: 11px;
}

.ranking-more {
  display: block;
  text-align: center;
  padding: 12px 0 0;
  color: #1890ff;
  text-decoration: none;
  font-size: 14px;
  transition: color 0.3s ease;
}

.ranking-more:hover {
  color: #40a9ff;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .ranking-board {
    padding: 12px;
  }
  
  .ranking-item {
    padding: 10px 0;
  }
  
  .ranking-title {
    font-size: 13px;
  }
  
  .ranking-stats {
    display: none;
  }
}
</style>